package com.sphd.beautysalon.adapters;

import android.content.Context;
import android.text.TextUtils;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sphd.beautysalon.info.FoodInfo;
import com.sphd.beautysalon.info.SalesInfo;
import com.sphd.beautysalon.utils.Constant;
import com.sphd.beautysalon.R;
import com.wzh.frame.utils.BigDisMailUtils;

import java.util.List;

/**
 * Created by Hu on 2016/11/8.
 */

public class OrderParticalarsAdapter extends BaseQuickAdapter<FoodInfo> {
    SalesInfo salesInfo;
    Context context;

    public OrderParticalarsAdapter(int layoutResId, List<FoodInfo> data, SalesInfo salesInfo, Context context) {
        super(layoutResId, data);
        this.salesInfo = salesInfo;
        this.context = context;
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, FoodInfo foodInfo) {
        if (salesInfo.getOrder_pay() == 0) {
            if (TextUtils.isEmpty(salesInfo.getOrder_memcard())) {
                baseViewHolder.setTextColor(R.id.real_money, context.getResources().getColor(R.color.red))
                        .setTextColor(R.id.restaurant_money, context.getResources().getColor(R.color.my_black))
                        .setText(R.id.all_money, turn(foodInfo.getDetail_price() * foodInfo.getDetail_dnumber()));
            } else {
                baseViewHolder.setTextColor(R.id.real_money, context.getResources().getColor(R.color.my_black))
                        .setTextColor(R.id.restaurant_money, context.getResources().getColor(R.color.orange))
                        .setText(R.id.all_money, turn(foodInfo.getDetail_vipprice() * foodInfo.getDetail_dnumber()));
            }
        } else {
            if (salesInfo.getOrder_lastprice() == 0) {
                baseViewHolder.setTextColor(R.id.real_money, context.getResources().getColor(R.color.indigo_500))
                        .setText(R.id.all_money, turn(foodInfo.getDetail_price() * foodInfo.getDetail_dnumber()));
            } else {
                baseViewHolder.setTextColor(R.id.real_money, context.getResources().getColor(R.color.my_black))
                        .setText(R.id.all_money, turn(foodInfo.getDetail_vipprice() * foodInfo.getDetail_dnumber()));
            }
        }

        baseViewHolder.setText(R.id.restaurant_name, foodInfo.getDetail_dname()).setText(R.id.restaurant_num, String.valueOf(foodInfo.getDetail_dnumber()))
                .setText(R.id.restaurant_money, turn(foodInfo.getDetail_vipprice()))
                .setText(R.id.real_money, turn(foodInfo.getDetail_price()));

    }

    public String turn(Object val) {
        return BigDisMailUtils.turnTrim(val, Constant.DECIMAL_POINT);
    }
}
